package java_class_work.week07.loginDemo01;

import java_class_work.week07.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Auther: admin
 * @Date: 2022/10/25 10:12
 * @Description:
 */

public class Login01 {
    public static void main(String[] args) {
        Connection connection = JDBCUtils.getConnection();
        String sql = "select * from user where username = ?";
        try {
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"admin");

            ResultSet rs = ps.executeQuery();
            rs.next();
            if ("123".equals(rs.getString("password"))) {
                System.out.println("success");
            }else{
                System.out.println("defeat");
            }
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
